package cn.xmkeshe.back.impl;

import cn.xmkeshe.back.IOrderDeServiceBack;
import cn.xmkeshe.dao.IOrderDeDao;
import cn.xmkeshe.model.OrderDe;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class IOrderDeServiceBackImpl implements IOrderDeServiceBack {

  @Resource
  private IOrderDeDao iOrderDeDao;


  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> findByOrid(int currentPage, int lineSize, String orid) {
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("data",iOrderDeDao.findByOrid((currentPage-1)*lineSize, lineSize,orid));
    map.put("count",iOrderDeDao.getCount());
    return map;
  }

  //  查询未审核订单
  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> listSplitByStatus(int currentPage, int lineSize) {
    Map<String,Object> result = new HashMap<String, Object>();
    result.put("start",(currentPage-1)*lineSize);
    result.put("lineSize",lineSize);
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("allOrderDe",iOrderDeDao.findAllSplit(result));
    map.put("allCount",iOrderDeDao.getAllCount());
    return map;
  }

//  查询已审核订单
  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> listSplitByStatus1(int currentPage, int lineSize) {
    Map<String,Object> result = new HashMap<String, Object>();
    result.put("start",(currentPage-1)*lineSize);
    result.put("lineSize",lineSize);
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("OrderDe",iOrderDeDao.findAllSplitByStatus(result));
    map.put("Count",iOrderDeDao.getAllCountByStatus());
    return map;
  }

  @Override
  @Transactional(propagation = Propagation.REQUIRED)
  public boolean edit(OrderDe orderDe) {
    return iOrderDeDao.doUpdateByStatus(orderDe);
  }

  @Override
  public boolean editOrderDeStatus(String orid) {
    return iOrderDeDao.doUpdateByStatusa(orid);
  }

//  查询已完结订单
  @Override
  public Map<String, Object> listSplitByStatus2(int currentPage, int lineSize) {
    Map<String,Object> result = new HashMap<String, Object>();
    result.put("start",(currentPage-1)*lineSize);
    result.put("lineSize",lineSize);
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("OrderDe",iOrderDeDao.findAllSplitByStatus1(result));
    map.put("Count",iOrderDeDao.getAllCountByStatus1());
    System.out.println(map);
    return map;
  }

  @Override
  @Transactional(propagation = Propagation.REQUIRED)
  public boolean editCaccount(OrderDe orderDe) {
    return iOrderDeDao.editCaccount(orderDe);
  }

  @Override
  @Transactional(propagation = Propagation.REQUIRED)
  public boolean editAaccount(OrderDe orderDe) {
    return iOrderDeDao.editAaccount(orderDe);
  }

  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> findCAccount(int currentPage, int lineSize) {
    Map<String,Object> result = new HashMap<String, Object>();
    result.put("start",(currentPage-1)*lineSize);
    result.put("lineSize",lineSize);
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("OrderDe",iOrderDeDao.findCAccount(result));
    map.put("Count",iOrderDeDao.getCount());
    System.out.println(map);
    return map;
  }
}
